package com.skybai.common;

import org.apache.ibatis.io.Resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigUtil {
    private static final Logger log = LoggerFactory.getLogger(ConfigUtil.class);
    public static File file;
    public static final Properties property;

    static {
        InputStream inputStream = null;
        property = new Properties();
        try {
            inputStream = Resources.getResourceAsStream("system-config.properties");
            property.load(inputStream);
        } catch (IOException e) {
            log.error("system-config.properties文件加载错误");
            e.printStackTrace();
        }

        try {
            file = new File(ConfigUtil.property.getProperty("output_path"));
            if (!file.exists()) {
                boolean mkdir = file.getParentFile().mkdir();
                if (mkdir) {
                    boolean newFile = file.createNewFile();
                    if (!newFile) {
                        log.error("创建文件失败");
                        throw new IOException();
                    }
                }
            }

        } catch (IOException e) {
            log.error("文件输出流创建异常");
            e.printStackTrace();
        }
    }
}
